package tuling.netty.readtime;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author RenGaoshuai
 * @date 2023/11/30 11:12
 * @description
 */
public class ReadtimeClientHandler extends ChannelInboundHandlerAdapter {

    /**
     * 连接建立后调用该方法
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        //像通道中写入数据
        ctx.writeAndFlush("HelloServer,I`m client");
    }

    /***
     * 读取通道中的数据
     * @param ctx
     * @param msg
     * @throws Exception
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("客户端接收到服务端发送的消息："+msg);
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        System.out.println("chaoshi-client");
    }
}
